GBML manual / Rooms

region_at

The region at a place in the world, as a region word like rg_forest: a place anywhere in the world the player is in, not only the part that is on screen. Handy for a roaming enemy that must stay out of the crypt. In a long room cut into regions it is a place in that room. -1 for a place outside the world or the room.

Syntax

region_at(x, y) -> int

Arguments

NameType
xreal
yreal

Returns

int

Description

The region at a place in the world, as a region word like rg_forest. The place can be anywhere in the world the player is in, not only the part that is on screen, so it works for an enemy that roams far from the player or a door that must know where it leads. It is -1 for a place outside the world.

Places are world places, like every other x and y in a game with a world: (0, 0) is the top-left of the world.

In a long room (a room longer or taller than one screen, cut into regions in Room Properties) it answers for a place in that room: (0, 0) is the room's top-left. It is -1 for a place outside the room, and in a room that has no regions.

Example

if (region_at(x + 16, y) == rg_crypt) {
    x -= 1;
}

Keeps this object out of the crypt: it backs away when the place 16 pixels to its right is in it.

See also: region_currentroam_boundaryWhat a region does in the game